package com.fairytask.utils
{
	import flash.geom.Point;

	public class Vec2D extends Object
	{
		public function Vec2D(arg1:Number=0, arg2:Number=0)
		{
			super();
			x = arg1;
			y = arg2;
			return;
		}
		
		public function cross(arg1:Vec2D):Number
		{
			return x * arg1.y - y * arg1.x;
		}
		
		public function divVec(arg1:Vec2D):Vec2D
		{
			return new Vec2D(x / arg1.x, y / arg1.y);
		}
		
		public function toString():String
		{
			return x.toString() + " " + y.toString();
		}
		
		public function dot(arg1:Vec2D):Number
		{
			var loc1:*=x * arg1.x + y * arg1.y;
			return loc1;
		}
		
		public function mulN(arg1:Number):void
		{
			x = x * arg1;
			y = y * arg1;
			return;
		}
		
		public function addN(arg1:Number):void
		{
			x = x + arg1;
			y = y + arg1;
			return;
		}
		
		public function subN(arg1:Number):void
		{
			x = x - arg1;
			y = y - arg1;
			return;
		}
		
		public function get point():flash.geom.Point
		{
			return new flash.geom.Point(x, y);
		}
		
		public function isLeft(arg1:Vec2D):Boolean
		{
			return cross(arg1) >= 0 ? true : false;
		}
		
		public function mulV(arg1:Vec2D):void
		{
			x = x * arg1.x;
			y = y * arg1.y;
			return;
		}
		
		public function get angle():Number
		{
			var loc1:*=Math.atan2(y, x) * 180 / Math.PI;
			if (loc1 < 0) 
			{
				loc1 = loc1 + 360;
			}
			return loc1;
		}
		
		public function get vec():Vec2D
		{
			return new Vec2D(x, y);
		}
		
		public function addV(arg1:Vec2D):void
		{
			x = x + arg1.x;
			y = y + arg1.y;
			return;
		}
		
		public function subV(arg1:Vec2D):void
		{
			x = x - arg1.x;
			y = y - arg1.y;
			return;
		}
		
		public function project(arg1:Vec2D):Vec2D
		{
			var loc1:*=dot(arg1);
			var loc2:*=arg1.dot(arg1);
			var loc3:*=loc1 / loc2;
			var loc4:*;
			return loc4 = arg1.mulNum(loc3);
		}
		
		public function get len():Number
		{
			return Math.sqrt(x * x + y * y);
		}
		
		public function divN(arg1:Number):void
		{
			x = x / arg1;
			y = y / arg1;
			return;
		}
		
		public function set point(arg1:flash.geom.Point):void
		{
			x = arg1.x;
			y = arg1.y;
			return;
		}
		
		public function mulNum(arg1:Number):Vec2D
		{
			return new Vec2D(x * arg1, y * arg1);
		}
		
		public function getAngle(arg1:Vec2D):Number
		{
			var loc1:*=nDot(arg1);
			return Math.acos(loc1) * 180 / Math.PI;
		}
		
		public function divV(arg1:Vec2D):void
		{
			x = x / arg1.x;
			y = y / arg1.y;
			return;
		}
		
		public function subNum(arg1:Number):Vec2D
		{
			return new Vec2D(x - arg1, y - arg1);
		}
		
		public function get normal():Vec2D
		{
			return new Vec2D(-y, x);
		}
		
		public function set vec(arg1:Vec2D):void
		{
			x = arg1.x;
			y = arg1.y;
			return;
		}
		
		public function get reverse():Vec2D
		{
			return new Vec2D(-x, -y);
		}
		
		public function addNum(arg1:Number):Vec2D
		{
			return new Vec2D(x + arg1, y + arg1);
		}
		
		public function set angle(arg1:Number):void
		{
			var loc1:*=arg1 * Math.PI / 180;
			x = Math.cos(loc1);
			y = Math.sin(loc1);
			return;
		}
		
		public function normalize():void
		{
			var loc1:*=len;
			var loc2:*=new Vec2D(0, 0);
			loc2.x = x / loc1;
			loc2.y = y / loc1;
			vec = loc2;
			return;
		}
		
		/**
		 * 取得二级Vector 
		 * @param pVec
		 * @return 
		 * 
		 */
		public function subVec(pVec:Vec2D):Vec2D
		{
			return new Vec2D(x - pVec.x, y - pVec.y);
		}
		
		public function divNum(arg1:Number):Vec2D
		{
			return new Vec2D(x / arg1, y / arg1);
		}
		
		public function mulVec(arg1:Vec2D):Vec2D
		{
			return new Vec2D(x * arg1.x, y * arg1.y);
		}
		
		public function addVec(arg1:Vec2D):Vec2D
		{
			return new Vec2D(x + arg1.x, y + arg1.y);
		}
		
		public function nDot(arg1:Vec2D):Number
		{
			var loc1:*=normalized;
			var loc2:*=arg1.normalized;
			var loc3:*;
			return loc3 = loc1.x * loc2.x + loc1.y * loc2.y;
		}
		
		public function get len2():Number
		{
			return x * x + y * y;
		}
		
		public function get normalized():Vec2D
		{
			var loc1:*=len;
			var loc2:*=new Vec2D(0, 0);
			loc2.x = x / loc1;
			loc2.y = y / loc1;
			return loc2;
		}
		
		public var x:Number=0;
		
		public var y:Number=0;
	}
}